<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link type="text/css" rel="stylesheet" href="css/style.css"/>
    <!--[if IE 6]>
    <script src="js/iepng.js" type="text/javascript"></script>
    <script type="text/javascript">
        EvPNG.fix('div, ul, img, li, input, a');
    </script>
    <![endif]-->

    <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="js/menu.js"></script>
    <script type="text/javascript" src="js/select.js"></script>
    <script type="text/javascript" src="js/vue.min.js"></script>
    <script type="text/javascript" src="js/axios.min.js"></script>

    <title>尤洪</title>
</head>
<body>
<!--Begin Header Begin-->
<div id="head">
    <div class="soubg">
        <div class="sou">
            <!--Begin 所在收货地区 Begin-->
            <span class="s_city_b">
        	<span class="fl">送货至：</span>
            <span class="s_city">
            	<span>四川</span>
                <div class="s_city_bg">
                	<div class="s_city_t"></div>
                    <div class="s_city_c">
                    	<h2>请选择所在的收货地区</h2>
                        <table border="0" class="c_tab" style="width:235px; margin-top:10px;" cellspacing="0"
                               cellpadding="0">
                          <tr>
                            <th>A</th>
                            <td class="c_h"><span>安徽</span><span>澳门</span></td>
                          </tr>
                          <tr>
                            <th>B</th>
                            <td class="c_h"><span>北京</span></td>
                          </tr>
                          <tr>
                            <th>C</th>
                            <td class="c_h"><span>重庆</span></td>
                          </tr>
                          <tr>
                            <th>F</th>
                            <td class="c_h"><span>福建</span></td>
                          </tr>
                          <tr>
                            <th>G</th>
                            <td class="c_h"><span>广东</span><span>广西</span><span>贵州</span><span>甘肃</span></td>
                          </tr>
                          <tr>
                            <th>H</th>
                            <td class="c_h"><span>河北</span><span>河南</span><span>黑龙江</span><span>海南</span><span>湖北</span><span>湖南</span></td>
                          </tr>
                          <tr>
                            <th>J</th>
                            <td class="c_h"><span>江苏</span><span>吉林</span><span>江西</span></td>
                          </tr>
                          <tr>
                            <th>L</th>
                            <td class="c_h"><span>辽宁</span></td>
                          </tr>
                          <tr>
                            <th>N</th>
                            <td class="c_h"><span>内蒙古</span><span>宁夏</span></td>
                          </tr>
                          <tr>
                            <th>Q</th>
                            <td class="c_h"><span>青海</span></td>
                          </tr>
                          <tr>
                            <th>S</th>
                            <td class="c_h"><span>上海</span><span>山东</span><span>山西</span><span class="c_check">四川</span><span>陕西</span></td>
                          </tr>
                          <tr>
                            <th>T</th>
                            <td class="c_h"><span>台湾</span><span>天津</span></td>
                          </tr>
                          <tr>
                            <th>X</th>
                            <td class="c_h"><span>西藏</span><span>香港</span><span>新疆</span></td>
                          </tr>
                          <tr>
                            <th>Y</th>
                            <td class="c_h"><span>云南</span></td>
                          </tr>
                          <tr>
                            <th>Z</th>
                            <td class="c_h"><span>浙江</span></td>
                          </tr>
                        </table>
                    </div>
                </div>
            </span>
        </span>
            <!--End 所在收货地区 End-->
            <span class="fr">
        	<span class="fl" v-show="loginUser===''">你好，请<a href="Login.html">登录</a>&nbsp;
                <a href="Regist.html" style="color:#ff4e00;">免费注册</a>&nbsp;|&nbsp;
            </span>
            <span class="fl" v-show="loginUser!==''">
                 <a href="Member_Order.html">我的订单</a>&nbsp;|
                 <a href="Member_UserInfo.html">后台</a>&nbsp;|
                 <a href="JavaScript:void(0)" @click="logout">注销</a>&nbsp;|
            </span>
        	<span class="ss">
            	<div class="ss_list">
                	<a href="#">收藏夹</a>
                    <div class="ss_list_bg">
                    	<div class="s_city_t"></div>
                        <div class="ss_list_c">
                        	<ul>
                            	<li><a href="#">我的收藏夹</a></li>
                                <li><a href="#">我的收藏夹</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="ss_list">
                	<a href="#">客户服务</a>
                    <div class="ss_list_bg">
                    	<div class="s_city_t"></div>
                        <div class="ss_list_c">
                        	<ul>
                            	<li><a href="#">客户服务</a></li>
                                <li><a href="#">客户服务</a></li>
                                <li><a href="#">客户服务</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="ss_list">
                	<a href="#">网站导航</a>
                    <div class="ss_list_bg">
                    	<div class="s_city_t"></div>
                        <div class="ss_list_c">
                        	<ul>
                            	<li><a href="#">网站导航</a></li>
                                <li><a href="#">网站导航</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </span>
            <span class="fl">|&nbsp;关注我们：</span>
            <span class="s_sh"><a href="#" class="sh1">新浪</a><a href="#" class="sh2">微信</a></span>
            <span class="fr">|&nbsp;<a href="#">手机版&nbsp;<img src="images/s_tel.png" align="absmiddle"/></a></span>
        </span>
        </div>
    </div>
    <div class="top">
        <div class="logo"><a href="Index.html"><img src="images/logo.png"/></a></div>
    </div>
</div>
<!--End Header End-->
<div id="body">
    <div class="i_bg bg_color">
        <!--Begin 用户中心 Begin -->
        <div class="m_content">
            <div class="m_left">
                <div class="left_n">管理中心</div>
                <div class="left_m">
                    <div class="left_m_t t_bg1">订单中心</div>
                    <ul>
                        <li><a href="Member_Order.html">我的订单</a></li>
                        <li v-show="loginUser.type===1"><a href="Member_OrderManage.html">订单管理</a></li>
                        <li><a href="Member_Address.html">收货地址</a></li>
                    </ul>
                </div>
                <div class="left_m">
                    <div class="left_m_t t_bg2">用户中心</div>
                    <ul>
                        <li><a href="Member_UserInfo.html">用户信息</a></li>
                        <li><a href="Member_UserPwd.html">修改密码</a></li>
                        <li v-show="loginUser.type===1"><a href="Member_UserManage.html">用户管理</a></li>
                        <li><a href="Member_Collect.html">我的收藏</a></li>
                    </ul>
                </div>
                <div class="left_m" v-show="loginUser.type===1">
                    <div class="left_m_t t_bg3">商品中心</div>
                    <ul>
                        <li><a href="Member_ProManage.html">商品管理</a></li>
                        <li><a href="Member_CateManage.html">类型管理</a></li>
                    </ul>
                </div>
                <div class="left_m">
                    <div class="left_m_t t_bg3">资讯中心</div>
                    <ul>
                        <li><a href="Member_NewsManage.html">全部资讯</a></li>
                    </ul>
                </div>
            </div>
            <div class="m_right">
                <div class="mem_t">添加商品</div>
                <table border="0" class="mon_tab" style="width:870px; margin-bottom:20px;" cellspacing="0"
                       cellpadding="0">
                    <tbody>
                    <input type="hidden" v-model="form.id">
                    <tr>
                        <td width="30%" style="text-align: center">一级分类</td>
                        <td>
                            <select v-model="form.categoryLevel1Id" @change="loadCateTwo">
                                <option v-for="one in CateOne" :value="one.id">{{one.name}}</option>
                            </select>
                        </td>
                    </tr>
                    <tr v-if="(type==='2' || type==='3') && form.categoryLevel2Id!==0">
                        <td width="30%" style="text-align: center">二级分类</td>
                        <td>
                            <select v-model="form.categoryLevel2Id" @change="loadCateThree">
                                <option v-for="two in CateTwo" :value="two.id">{{two.name}}</option>
                            </select>
                        </td>
                    </tr>
                    <tr v-if="type==='3' && form.categoryLevel3Id!==0 ">
                        <td width="30%" style="text-align: center">三级分类</td>
                        <td>
                            <select v-model="form.categoryLevel3Id">
                                <option v-for="three in CateThree" :value="three.id">{{three.name}}</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" style="text-align: center">商品名称</td>
                        <td>
                            <input type="text" v-model="form.name" @blur="checkName">（必填）
                            <span style="color: red">{{check1}}</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" style="text-align: center">商品图片</td>
                        <td>
                            <img :src="'http://192.168.189.129:8091/'+form.fileName" width="100"/>
                            <input type="file" id="file" @blur="checkFileName">
                            <span style="color: red">{{check2}}</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" style="text-align: center">单价</td>
                        <td>
                            <input type="text" v-model="form.price" @blur="checkPrice">
                            <span style="color: red">{{check3}}</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" style="text-align: center">库存</td>
                        <td>
                            <input type="text" v-model="form.stock" @blur="checkStock">
                            <span style="color: red">{{check4}}</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" style="text-align: center">描述</td>
                        <td>
                            <textarea cols="20" rows="1" v-model="form.description"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" style="text-align: center"></td>
                        <td>
                            <input type="button" value="添加" @click="addPro">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <!--End 用户中心 End-->
        <!--Begin Footer Begin -->
        <div class="b_btm_bg b_btm_c">
            <div class="b_btm">
                <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;"
                       cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="72"><img src="images/b1.png" width="62" height="62"/></td>
                        <td><h2>正品保障</h2>正品行货 放心购买</td>
                    </tr>
                </table>
                <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;"
                       cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="72"><img src="images/b2.png" width="62" height="62"/></td>
                        <td><h2>满38包邮</h2>满38包邮 免运费</td>
                    </tr>
                </table>
                <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;"
                       cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="72"><img src="images/b3.png" width="62" height="62"/></td>
                        <td><h2>天天低价</h2>天天低价 畅选无忧</td>
                    </tr>
                </table>
                <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;"
                       cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="72"><img src="images/b4.png" width="62" height="62"/></td>
                        <td><h2>准时送达</h2>收货时间由你做主</td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="b_nav">
            <dl>
                <dt><a href="#">新手上路</a></dt>
                <dd><a href="#">售后流程</a></dd>
                <dd><a href="#">购物流程</a></dd>
                <dd><a href="#">订购方式</a></dd>
                <dd><a href="#">隐私声明</a></dd>
                <dd><a href="#">推荐分享说明</a></dd>
            </dl>
            <dl>
                <dt><a href="#">配送与支付</a></dt>
                <dd><a href="#">货到付款区域</a></dd>
                <dd><a href="#">配送支付查询</a></dd>
                <dd><a href="#">支付方式说明</a></dd>
            </dl>
            <dl>
                <dt><a href="#">会员中心</a></dt>
                <dd><a href="#">资金管理</a></dd>
                <dd><a href="#">我的收藏</a></dd>
                <dd><a href="#">我的订单</a></dd>
            </dl>
            <dl>
                <dt><a href="#">服务保证</a></dt>
                <dd><a href="#">退换货原则</a></dd>
                <dd><a href="#">售后服务保证</a></dd>
                <dd><a href="#">产品质量保证</a></dd>
            </dl>
            <dl>
                <dt><a href="#">联系我们</a></dt>
                <dd><a href="#">网站故障报告</a></dd>
                <dd><a href="#">购物咨询</a></dd>
                <dd><a href="#">投诉与建议</a></dd>
            </dl>
            <div class="b_tel_bg">
                <a href="#" class="b_sh1">新浪微博</a>
                <a href="#" class="b_sh2">腾讯微博</a>
                <p>
                    服务热线：<br/>
                    <span>400-123-4567</span>
                </p>
            </div>
            <div class="b_er">
                <div class="b_er_c"><img src="images/er.gif" width="118" height="118"/></div>
                <img src="images/ss.png"/>
            </div>
        </div>
        <div class="btmbg">
            <div class="btm">
                备案/许可证编号：蜀ICP备12009302号-1-www.dingguagua.com Copyright © 2015-2018 尤洪商城网 All Rights Reserved. 复制必究 ,
                Technical Support: Dgg Group <br/>
                <img src="images/b_1.gif" width="98" height="33"/><img src="images/b_2.gif" width="98" height="33"/><img
                    src="images/b_3.gif" width="98" height="33"/><img src="images/b_4.gif" width="98" height="33"/><img
                    src="images/b_5.gif" width="98" height="33"/><img src="images/b_6.gif" width="98" height="33"/>
            </div>
        </div>
        <!--End Footer End -->
    </div>
</div>
<script type="text/javascript">
    let head = new Vue({
        el: "#head",
        data: {
            loginUser: "",
            name: "",
        },
        created() {
            this.getUser();
        },
        methods: {
            getUser() {
                axios("/index/getUser").then(res => {
                    this.loginUser = res.data;
                    if (this.loginUser === '') {
                        alert("用户未登录！");
                        window.location.href = "Index.html";
                    } else {
                        if (this.loginUser.type === 0) {
                            alert("权限不足！");
                            window.location.href = "Index.html";
                        }
                    }
                })
            },
            logout() {
                axios("/index/logout").then(res => {
                    this.getUser();
                    alert("退出成功！");
                })
            },
        }
    })

    let body = new Vue({
        el: "#body",
        data: {
            loginUser: "",
            type: "3",
            form: {
                id: "",
                categoryLevel1Id: "",
                categoryLevel2Id: "",
                categoryLevel3Id: "",
                name: "",
                price: "",
                stock: "",
                description: "",
                file: "",
            },
            CateOne: "",
            CateTwo: "",
            CateThree: "",
            check1: "",
            check2: "",
            check3: "",
            check4: "",
            flag1: "",
            flag2: "",
            flag3: "",
            flag4: "",
            cat1: "",
            cat2: "",
            cat3: "",
        },
        created() {
            this.getUser();
            this.loadPro();
        },
        methods: {
            getUser() {
                axios("/index/getUser").then(res => {
                    this.loginUser = res.data;
                })
            },
            loadPro() {
                let url = window.location.href;
                let arr = url.split("=");
                let id = decodeURI(arr[1]);
                axios("pro/loadPro/" + id).then(res => {
                    this.form = res.data;
                    this.form.id = id;
                    this.cat1 = this.form.categoryLevel1Id;
                    this.cat2 = this.form.categoryLevel2Id;
                    this.cat3 = this.form.categoryLevel3Id;
                    this.loadCateOne();
                })
            },
            loadCateOne() {
                axios("/cate/loadCateOne").then(res => {
                    this.CateOne = res.data;
                    this.loadCateTwo();
                })
            },
            loadCateTwo() {
                axios("/cate/loadCateTwo/" + this.form.categoryLevel1Id).then(res => {
                    this.CateTwo = res.data;
                    if (this.CateTwo[0] === undefined) {
                        this.form.categoryLevel2Id = 0;
                    } else if (this.cat1 !== this.form.categoryLevel1Id) {
                        this.form.categoryLevel2Id = this.CateTwo[0].id;
                    } else if (this.cat1 === this.form.categoryLevel1Id) {
                        this.form.categoryLevel2Id = this.cat2;
                    }
                    this.loadCateThree();
                })
            },
            loadCateThree() {
                axios("/cate/loadCateThree/" + this.form.categoryLevel2Id).then(res => {
                    this.CateThree = res.data;
                    if (this.CateThree[0] === undefined) {
                        this.form.categoryLevel3Id = 0;
                    } else if (this.cat2 !== this.form.categoryLevel2Id) {
                        this.form.categoryLevel3Id = this.CateThree[0].id;
                    } else if (this.cat2 === this.form.categoryLevel2Id) {
                        this.form.categoryLevel3Id = this.cat3;
                    }
                })
            },
            checkName() {
                if (this.form.name === '') {
                    this.check1 = "商品名称不能为空";
                    this.flag1 = false;
                } else {
                    this.check1 = "";
                    this.flag1 = true;
                }
            },
            checkFileName() {
                let fileList = document.getElementById("file").files[0];
                console.log(fileList);
                if (fileList === undefined) {
                    this.check2 = "";
                    this.flag2 = true;
                } else {
                    if (fileList.type === 'image/png' || fileList.type === 'image/jpg' || fileList.type === 'image/jpeg') {
                        if (fileList.size > 5 * 1024 * 1024) {
                            this.check2 = "商品图片大小超过5M";
                            this.flag2 = false;
                        } else {
                            this.check2 = "";
                            this.flag2 = true;
                        }
                    } else {
                        this.check2 = "商品图片格式不正确";
                        this.flag2 = false;
                    }
                }
            },
            checkPrice() {
                if (this.form.price === '') {
                    this.check3 = "价格不能为空";
                    this.flag3 = false;
                } else {
                    if (/(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/.test(this.form.price)) {
                        this.check3 = "";
                        this.flag3 = true;
                    } else {
                        this.check3 = "价格格式错误";
                        this.flag3 = false;
                    }
                }
            },
            checkStock() {
                if (this.form.stock === '') {
                    this.check4 = "库存数不能为空";
                    this.flag4 = false;
                } else {
                    if (/^[1-9]\d*$/.test(this.form.stock)) {
                        this.check4 = "";
                        this.flag4 = true;
                    } else {
                        this.check4 = "库存数必须为正整数";
                        this.flag4 = false;
                    }
                }
            },
            addPro() {
                this.checkName();
                this.checkFileName();
                this.checkPrice();
                this.checkStock();
                if (this.flag1 && this.flag2 && this.flag3 && this.flag4) {
                    let fileName = document.getElementById("file").files[0];
                    if (fileName === undefined) {
                        axios.post("pro/editProNoFile", this.form).then(res => {
                            if (res.data === true) {
                                alert("修改成功");
                                window.location.href = "Member_ProManage.html";
                            } else {
                                alert("修改失败");
                            }
                        })
                    } else {
                        let formData = new FormData();
                        formData.append("id", this.form.id);
                        formData.append("name", this.form.name);
                        formData.append("price", this.form.price);
                        formData.append("stock", this.form.stock);
                        formData.append("type", this.form.type);
                        formData.append("fileName", this.form.fileName);
                        formData.append("file", fileName);
                        formData.append("description", this.form.description);
                        formData.append("categoryLevel1Id", this.form.categoryLevel1Id);
                        formData.append("categoryLevel2Id", this.form.categoryLevel2Id);
                        formData.append("categoryLevel3Id", this.form.categoryLevel3Id);
                        axios({
                            url: "/pro/editProHasFile",
                            method: "post",
                            data: formData,
                            headers: {
                                "Content-Type": "multipart/form-data"
                            }
                        }).then(res => {
                            if (res.data === true) {
                                alert("修改成功");
                                window.location.href = "Member_ProManage.html";
                            } else {
                                alert("修改失败");
                            }
                        })
                    }
                }
            }

        }
    })
</script>
</body>


<!--[if IE 6]>
<script src="//letskillie6.googlecode.com/svn/trunk/2/zh_CN.js"></script>
<![endif]-->
</html>
